import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "练习",
      debugShowCheckedModeBanner: false,
      // localizationsDelegates: [
      //   GlobalMaterialLocalizations.delegate,
      //   GlobalWidgetsLocalizations.delegate
      // ],
      // supportedLocales: [
      //   const Locale("zh","CH"),
      //   const Locale("en","US")
      // ],
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      supportedLocales: [const Locale("zh", "CN"), const Locale("en", "US")],
      locale: Locale("en"),
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
        appBar: AppBar(
          title: Text("jiange"),
        ),
        body: MyContent(),
      ),
    );
  }
}

class MyContent extends StatefulWidget {
  @override
  _MyContentState createState() => _MyContentState();
}

class _MyContentState extends State<MyContent> with TickerProviderStateMixin {
  Animation animation;
  AnimationController controller;

  @override
  void initState() {
    controller = AnimationController(vsync: this,duration: Duration(seconds: 1));
    animation = Tween(begin: 0.0,end: 2.0*pi).animate(controller)..addStatusListener((status) {
      if(status == AnimationStatus.completed){
        print("完成");
        controller.reverse();
      }
      if(status == AnimationStatus.dismissed){
        print("返回完成");
        controller.forward();
      }
    });
    controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          width: 300,
          height: 300,
          color: Colors.green,
          child: AnimatedBuilder(
            animation: animation,
            builder: (context, child) {
              return Transform.rotate(angle: animation.value,child: child,);
            },
            child: FlutterLogo(curve: Curves.bounceOut,size: 40,),
          ),
        )
      ],
    );
  }
}
